<template>
  <div class="user-info">
    <el-dropdown>
      <span class="el-dropdown-link">
        <el-avatar
          size="small"
          src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
        ></el-avatar>
        <span class="name">{{ name }}</span>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="exit">
            <el-icon> <Bell /></el-icon> 退出
          </el-dropdown-item>
          <el-dropdown-item>
            <el-icon> <Stamp /></el-icon>用户</el-dropdown-item
          >
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
export default defineComponent({
  name: "UserInfo",
  setup() {
    const store = useStore();
    const router = useRouter();
    const name = computed(() => store.state.login.userInfo.name);
    const exit = () => {
      localStorage.removeItem("token");
      router.push({
        path: "/login",
      });
    };
    return {
      name,
      exit,
    };
  },
});
</script>

<style scoped lang="less">
.el-dropdown-link {
  display: flex;
  align-items: center;
  .name {
    margin-left: 10px;
  }
}
</style>
